package com.memory.admin.record;

import com.memory.common.utils.ResultVoUtil;
import com.memory.common.vo.ResultVo;
import com.memory.modules.business.domain.earn.CurDayPrice;
import com.memory.modules.business.domain.record.WithdrawRecord;
import com.memory.modules.business.service.record.WithdrawRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/business/withdraw/record")
@RequiredArgsConstructor
public class WithdrawRecordController {
    @Resource
    private WithdrawRecordService withdrawRecordService;

    @GetMapping("list")
    public String list(Model model, WithdrawRecord withdrawRecord) {
        ExampleMatcher matcher = ExampleMatcher.matching();
        Example<WithdrawRecord> example = Example.of(withdrawRecord, matcher);
        final Page<WithdrawRecord> page = withdrawRecordService.findPage(example);
        model.addAttribute("list", page.getContent());
        model.addAttribute("page", page);
        return "/business/record/withdraw/list";
    }

    @RequestMapping("/flag")
    @ResponseBody
    public ResultVo delete(@RequestParam(value = "ids", required = false) Long id){
        if (id != null){
            withdrawRecordService.flag(id);
            return ResultVoUtil.success("标记成功");
        }

        return ResultVoUtil.error("请传入需要标记处理的id");
    }

}
